/*
 * CSelectUtils.h
 *
 *  Created on: 2011-9-10
 *      Author: stargui
 */

#ifndef CPSELECTUTILS_H_
#define CPSELECTUTILS_H_

#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

#define FD_SETS_ENUM

#ifdef FD_SETS_ENUM
typedef enum
{
	P_FD_SETS_READ = 0,

	P_FD_SETS_WRITE = 1,

	P_FD_SETS_ERROR = 2,

	P_FD_SETS_COUNT = 3,

} P_FD_SETS_ENUMS;
#endif

class CPSelectUtils
{
private:

	int _maxhandle;

	fd_set _sets[P_FD_SETS_COUNT];

public:

	CPSelectUtils();

	virtual ~CPSelectUtils();

public:

	int InsertfdSets(int fd, P_FD_SETS_ENUMS sets);

	int Select( int selectSec = 0, int selectUsec = 0);

	bool CheckSets(int fd, P_FD_SETS_ENUMS sets);

	void static mSleep(unsigned int  MilliSecond);
};

#endif /* CPSELECTUTILS_H_ */
